﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MyK3CloudCore.IOC.K3Client;
using System;

namespace MyK3CloudCore.IOC;

public class K3CloudHelper
{
    public static K3CloudApiClient GetNewK3cloudClient(string configKey = default)
    {
        if (string.IsNullOrEmpty(configKey)) return new(K3IOCServiceCollectionExtensions.Configs);
        var builder = new ConfigurationBuilder().AddInMemoryCollection().AddJsonFile("appsettings.json", false).Build();
        var k3Config = builder.GetSection($"K3CLOUDCONFIG:{configKey}").Get<K3Config>();
        return k3Config == null ? throw new ArgumentNullException(configKey) : new(k3Config);
    }
}
